/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package frames;

import business.Foto;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ImageIcon;
import javax.swing.JFileChooser;
import principal.Principal;

/**
 *
 * @author jonas
 */
public class MainFrame extends javax.swing.JFrame {

    /**
     * Creates new form MainFrame
     */
    public MainFrame() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        carregarFoto_chooser = new javax.swing.JFileChooser();
        jPanel1 = new javax.swing.JPanel();
        enviarFoto_label = new javax.swing.JLabel();
        latitude_label = new javax.swing.JLabel();
        longitude_label = new javax.swing.JLabel();
        confirmar_botao = new javax.swing.JButton();
        latitude_texto = new javax.swing.JTextField();
        longitude_texto = new javax.swing.JTextField();
        barraDeMenu = new javax.swing.JMenuBar();
        arquivo_menu = new javax.swing.JMenu();
        enviarFoto_menu = new javax.swing.JMenuItem();
        sair_menu = new javax.swing.JMenuItem();
        sobre_menu = new javax.swing.JMenu();
        infoPlaces_menu = new javax.swing.JMenuItem();
        documentacao_menu = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("InfoPlaces 1.0");
        setResizable(false);

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));
        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jPanel1.setPreferredSize(new java.awt.Dimension(240, 400));

        enviarFoto_label.setFont(new java.awt.Font("Tempus Sans ITC", 0, 24)); // NOI18N
        enviarFoto_label.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        enviarFoto_label.setText("Enviar sua foto ");
        enviarFoto_label.setPreferredSize(new java.awt.Dimension(240, 400));
        enviarFoto_label.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                enviarFoto_labelMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(enviarFoto_label, javax.swing.GroupLayout.PREFERRED_SIZE, 235, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 1, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(enviarFoto_label, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
        );

        latitude_label.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        latitude_label.setText("Latitude:");

        longitude_label.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        longitude_label.setText("Longitude:");

        confirmar_botao.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        confirmar_botao.setText("Confirmar");
        confirmar_botao.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                confirmar_botaoActionPerformed(evt);
            }
        });

        latitude_texto.setEditable(false);

        longitude_texto.setEditable(false);

        arquivo_menu.setText("Arquivo");

        enviarFoto_menu.setText("Enviar Foto");
        arquivo_menu.add(enviarFoto_menu);

        sair_menu.setText("Sair");
        arquivo_menu.add(sair_menu);

        barraDeMenu.add(arquivo_menu);

        sobre_menu.setText("Sobre");

        infoPlaces_menu.setText("InfoPlaces");
        sobre_menu.add(infoPlaces_menu);

        documentacao_menu.setText("Documentação");
        sobre_menu.add(documentacao_menu);

        barraDeMenu.add(sobre_menu);

        setJMenuBar(barraDeMenu);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(108, 108, 108)
                        .addComponent(confirmar_botao)
                        .addContainerGap(49, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(latitude_label)
                            .addComponent(longitude_label))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(latitude_texto)
                            .addComponent(longitude_texto))
                        .addContainerGap())))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(latitude_label)
                            .addComponent(latitude_texto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(longitude_label)
                            .addComponent(longitude_texto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 221, Short.MAX_VALUE)
                        .addComponent(confirmar_botao))
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 310, Short.MAX_VALUE))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void enviarFoto_labelMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_enviarFoto_labelMouseClicked
//        carregarFoto_chooser = new JFileChooser();
//        
//        //Colocar Filtro
//        
//        int retorno = carregarFoto_chooser.showOpenDialog(null);
//        
//        if(retorno == JFileChooser.APPROVE_OPTION){
//            String caminhoFoto = carregarFoto_chooser.getSelectedFile().getAbsolutePath();
//            System.out.println(caminhoFoto);
////            try {
////                Foto foto = new Foto(caminhoFoto);
//                
//                latitude_texto.setEditable(true);
////                latitude_texto.setText(foto.getLatitude());
////                longitude_texto.setEditable(true);
////                longitude_texto.setText(foto.getLongitude());
//                
////                ImageIcon imagemLabel = new ImageIcon(foto.getFotoRetirada().getScaledInstance(240,400, 0));
//                
//                enviarFoto_label.setText("");
////                enviarFoto_label.setIcon(imagemLabel);
//                
////            } catch (IOException ex) {
//                //Colocar saida
//            }
//        } else {
//            //Colocar saida
//        }
    }//GEN-LAST:event_enviarFoto_labelMouseClicked

    private void confirmar_botaoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_confirmar_botaoActionPerformed
       String latitude = latitude_texto.getText();
       String longitude = longitude_texto.getText();
        
        if (!latitude.equals("") && !longitude.equals("")) {
            Principal principal = new Principal();
            try {
                principal.doProcess(latitude, longitude);
            } catch (InterruptedException ex) {
               //
            } catch (IOException ex) {
                //
            }
        }
    }//GEN-LAST:event_confirmar_botaoActionPerformed

    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new MainFrame().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenu arquivo_menu;
    private javax.swing.JMenuBar barraDeMenu;
    private javax.swing.JFileChooser carregarFoto_chooser;
    private javax.swing.JButton confirmar_botao;
    private javax.swing.JMenuItem documentacao_menu;
    private javax.swing.JLabel enviarFoto_label;
    private javax.swing.JMenuItem enviarFoto_menu;
    private javax.swing.JMenuItem infoPlaces_menu;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JLabel latitude_label;
    private javax.swing.JTextField latitude_texto;
    private javax.swing.JLabel longitude_label;
    private javax.swing.JTextField longitude_texto;
    private javax.swing.JMenuItem sair_menu;
    private javax.swing.JMenu sobre_menu;
    // End of variables declaration//GEN-END:variables
}
